//
//  InfoCell.m
//  ZzzzyManProject
//
//  Created by mac on 16/3/4.
//  Copyright © 2016年 ZzzzyMan@. All rights reserved.
//

#import "InfoCell.h"
#import "InfoItem.h"
#import "InfoItemArrow.h"
#import "InfoItemSwitch.h"

@implementation InfoCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString * identifier = @"infoCell";
    InfoCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        //修改背景颜色
        cell.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:222/255.0 green:222/255.0 blue:222/255.0 alpha:1];
    }
    return cell;
}

- (void)setItem:(InfoItem *)item {
    //给Cell赋值
    self.imageView.image = [UIImage imageNamed:item.optionImageName];
    self.textLabel.text = item.title;
    
    //判断是箭头还是开关
    if ([item isKindOfClass:[InfoItemArrow class]]) {
        self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right"]];
    }
    else if ([item isKindOfClass:[InfoItemSwitch class]]) {
        UISwitch * switchbtn = [[UISwitch alloc] init];
        switchbtn.on = true;
        self.accessoryView = switchbtn;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
}

@end
